<!DOCTYPE html>
<html lang="en">

<!-- Head tag -->
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="null">
    <meta name="keyword" content="null">
    <meta name="theme-color" content="#600090">
    <meta name="msapplication-navbutton-color" content="#600090">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="#600090">
    <link rel="shortcut icon" href="/assets/favicon.ico">
    <link rel="alternate" type="application/atom+xml" title="张小阳" href="/atom.xml">
    <link rel="stylesheet" href="https://cdn.bootcss.com/animate.css/3.5.2/animate.css">
    <link rel="stylesheet" href="https://cdn.bootcss.com/font-awesome/4.6.3/css/font-awesome.css">
    <title>
        
        JS函数式编程｜MillZhang&#39;s blog
        
    </title>

    <link rel="canonical" href="http://millzhang.github.io/2017/06/05/2017-note/08.JS函数式编程/">

    <!-- Bootstrap Core CSS -->
    <link rel="stylesheet" href="/css/bootstrap.min.css">

    <!-- Custom CSS -->
    <link rel="stylesheet" href="/css/blog-style.css">

    <!-- Pygments Github CSS -->
    <link rel="stylesheet" href="/css/syntax.css">
</head>

<!-- hack iOS CSS :active style -->
<body ontouchstart="" class="animated fadeIn">
<!-- Navigation -->
<nav class="navbar navbar-default navbar-custom navbar-fixed-top " id="nav-top" data-ispost = "true" data-istags="false
" data-ishome = "false" >
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header page-scroll">
            <button type="button" class="navbar-toggle">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand animated pulse" href="/">
                <span class="brand-logo">
                    MillZhang
                </span>
            </a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <!-- Known Issue, found by Hux:
            <nav>'s height woule be hold on by its content.
            so, when navbar scale out, the <nav> will cover tags.
            also mask any touch event of tags, unfortunately.
        -->
        <!-- /.navbar-collapse -->
        <div id="huxblog_navbar">
            <div class="navbar-collapse">
                <ul class="nav navbar-nav navbar-right">
                    <li>
                        <a href="/"><i class="fa fa-home"></i>主页</a>
                    </li>
                   <li>
                        <a href="/tags"><i class="fa fa-tags"></i>归档</a>
                    </li>
                    <li>
                        <a href="/about"><i class="fa fa-user"></i>关于</a>
                    </li>
                </ul>
            </div>
        </div>
    </div>
    <!-- /.container -->
</nav>
<script>
    // Drop Bootstarp low-performance Navbar
    // Use customize navbar with high-quality material design animation
    // in high-perf jank-free CSS3 implementation
//    var $body   = document.body;
    var $toggle = document.querySelector('.navbar-toggle');
    var $navbar = document.querySelector('#huxblog_navbar');
    var $collapse = document.querySelector('.navbar-collapse');

    $toggle.addEventListener('click', handleMagic)
    function handleMagic(e){
        if ($navbar.className.indexOf('in') > 0) {
        // CLOSE
            $navbar.className = " ";
            // wait until animation end.
            setTimeout(function(){
                // prevent frequently toggle
                if($navbar.className.indexOf('in') < 0) {
                    $collapse.style.height = "0px"
                }
            },400)
        }else{
        // OPEN
            $collapse.style.height = "auto"
            $navbar.className += " in";
        }
    }
</script>

<!-- Main Content -->

<!--only post-->

<header class="intro-header">
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1 text-center">
                <div class="post-heading">
                    <h1>JS函数式编程</h1>
                    
                    <span class="meta">
                         作者 MillZhang
                        <span>
                          日期 2017-06-05
                         </span>
                    </span>
                    <div class="tags text-center">
                        
                        <a class="tag" href="/tags/#javascript"
                           title="javascript">javascript</a>
                        
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="post-title-haojen">
        <span>
            JS函数式编程
        </span>
    </div>
    <div class="post-header-image">
        
            <img src="http://oritfw5nq.bkt.clouddn.com/wall-303.jpg?imageView2/0/format/jpg/interlace/1/q/85|watermark/2/text/QnkgTWlsbHpoYW5n/font/5b6u6L2v6ZuF6buR/fontsize/480/fill/I0ZERkRGRA==/dissolve/56/gravity/SouthEast/dx/10/dy/10|imageslim">
         
    </div>
</header>

<!-- Post Content -->
<article>
    <div class="container">
        <div class="row">
            <!-- Post Container -->
            <div class="col-lg-8 col-lg-offset-1 col-sm-9 post-container">
                <h3 id="概念"><a href="#概念" class="headerlink" title="概念"></a>概念</h3><blockquote>
<p>以函数作为主要载体的编程方式,用函数去拆解,抽象一般的表达式;</p>
</blockquote>
<h3 id="特点"><a href="#特点" class="headerlink" title="特点"></a>特点</h3><ul>
<li>语义清晰</li>
<li>可复用性好</li>
<li>可维护性好</li>
<li>作用域局限, 副作用小</li>
</ul>
<a id="more"></a>
<h3 id="基本的函数式编程"><a href="#基本的函数式编程" class="headerlink" title="基本的函数式编程"></a>基本的函数式编程</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div></pre></td><td class="code"><pre><div class="line"><span class="comment">// 数组中每个单词，首字母大写</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">// 一般写法</span></div><div class="line"><span class="keyword">const</span> arr = [<span class="string">'apple'</span>, <span class="string">'pen'</span>, <span class="string">'apple-pen'</span>];</div><div class="line"><span class="keyword">for</span>(<span class="keyword">const</span> i <span class="keyword">in</span> arr)&#123;</div><div class="line">  <span class="keyword">const</span> c = arr[i][<span class="number">0</span>];</div><div class="line">  arr[i] = c.toUpperCase() + arr[i].slice(<span class="number">1</span>);</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="built_in">console</span>.log(arr);</div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">// 函数式写法一</span></div><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">upperFirst</span>(<span class="params">word</span>) </span>&#123;</div><div class="line">  <span class="keyword">return</span> word[<span class="number">0</span>].toUpperCase() + word.slice(<span class="number">1</span>);</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">wordToUpperCase</span>(<span class="params">arr</span>) </span>&#123;</div><div class="line">  <span class="keyword">return</span> arr.map(upperFirst);</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="built_in">console</span>.log(wordToUpperCase([<span class="string">'apple'</span>, <span class="string">'pen'</span>, <span class="string">'apple-pen'</span>]));</div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">// 函数式写法二</span></div><div class="line"><span class="built_in">console</span>.log(arr.map(<span class="function"><span class="params">word</span>=&gt;</span>&#123;</div><div class="line">	<span class="keyword">return</span> word[<span class="number">0</span>].toUpperCase()+word.slice(<span class="number">1</span>)</div><div class="line">&#125;));</div><div class="line"></div><div class="line"><span class="comment">//另一种写法</span></div><div class="line"><span class="built_in">console</span>.log(<span class="built_in">Array</span>.prototype.map.call(arr, word =&gt; word[<span class="number">0</span>].toUpperCase() + word.slice(<span class="number">1</span>)));</div></pre></td></tr></table></figure>
<blockquote>
<p> <code>map()</code> 方法返回一个由原数组中的每个元素调用一个指定方法后的返回值组成的新数组。</p>
</blockquote>
<h3 id="链式优化"><a href="#链式优化" class="headerlink" title="链式优化"></a>链式优化</h3><blockquote>
<p><code>lodash</code>:一个具有一致接口、模块化、高性能等特性的 JavaScript 工具库;主要是为了延迟计算.</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div></pre></td><td class="code"><pre><div class="line"><span class="comment">//一个简单的加减法链式计算</span></div><div class="line"></div><div class="line"><span class="keyword">const</span> utils = &#123;</div><div class="line">    chain(a)&#123;</div><div class="line">        <span class="keyword">this</span>._temp = a;</div><div class="line">        <span class="keyword">return</span> <span class="keyword">this</span>;</div><div class="line">    &#125;,</div><div class="line">    sum(a)&#123;<span class="comment">//加</span></div><div class="line">        <span class="keyword">this</span>._temp+=a;</div><div class="line">        <span class="keyword">return</span> <span class="keyword">this</span>;</div><div class="line">    &#125;,</div><div class="line">    sub(a)&#123;<span class="comment">//减</span></div><div class="line">        <span class="keyword">this</span>._temp-=a;</div><div class="line">        <span class="keyword">return</span> <span class="keyword">this</span>;</div><div class="line">    &#125;,</div><div class="line">    value()&#123;</div><div class="line">        <span class="keyword">const</span> _temp = <span class="keyword">this</span>._temp;</div><div class="line">        <span class="keyword">this</span>._temp = <span class="literal">undefined</span>;<span class="comment">//清空临时变量</span></div><div class="line">        <span class="keyword">return</span> _temp;</div><div class="line">    &#125;</div><div class="line">&#125;</div><div class="line"><span class="built_in">console</span>.log(utils.chain(<span class="number">1</span>).sum(<span class="number">2</span>).sum(<span class="number">3</span>).sub(<span class="number">4</span>).value());<span class="comment">//2</span></div></pre></td></tr></table></figure>
<h3 id="链式对比回调和Promise模式"><a href="#链式对比回调和Promise模式" class="headerlink" title="链式对比回调和Promise模式"></a>链式对比回调和Promise模式</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div></pre></td><td class="code"><pre><div class="line"><span class="comment">// 回调函数</span></div><div class="line"><span class="keyword">import</span> $ <span class="keyword">from</span> <span class="string">'jquery'</span>;</div><div class="line">$.post(<span class="string">'a/url/to/target'</span>, (rs) =&gt; &#123;</div><div class="line">  <span class="keyword">if</span>(rs)&#123;</div><div class="line">    $.post(<span class="string">'a/url/to/another/target'</span>, (rs2) =&gt; &#123;</div><div class="line">      <span class="keyword">if</span>(rs2)&#123;</div><div class="line">        $.post(<span class="string">'a/url/to/third/target'</span>);</div><div class="line">      &#125;</div><div class="line">    &#125;);</div><div class="line">  &#125;</div><div class="line">&#125;);</div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">// Promise</span></div><div class="line"><span class="keyword">import</span> request <span class="keyword">from</span> <span class="string">'catta'</span>;  </div><div class="line"><span class="comment">// catta 是一个轻量级请求工具，支持 fetch,jsonp,ajax，无依赖</span></div><div class="line">request(<span class="string">'a/url/to/target'</span>)</div><div class="line">  .then(<span class="function"><span class="params">rs</span> =&gt;</span> rs ? $.post(<span class="string">'a/url/to/another/target'</span>) : <span class="built_in">Promise</span>.reject())</div><div class="line">  .then(<span class="function"><span class="params">rs2</span> =&gt;</span> rs2 ? $.post(<span class="string">'a/url/to/third/target'</span>) : <span class="built_in">Promise</span>.reject());</div></pre></td></tr></table></figure>
<p>随着回调函数嵌套层级和单层复杂度增加，它将会变得臃肿且难以维护，而 Promise 的链式结构，在高复杂度时，仍能纵向扩展，而且层次隔离很清晰。</p>
<h3 id="常见的函数式编程"><a href="#常见的函数式编程" class="headerlink" title="常见的函数式编程"></a>常见的函数式编程</h3><h4 id="闭包-Closure"><a href="#闭包-Closure" class="headerlink" title="闭包(Closure)"></a>闭包(Closure)</h4><blockquote>
<p>可以保留局部变量不被释放的代码块,称为闭包</p>
</blockquote>
<p>闭包创造的条件</p>
<ul>
<li>存在内、外两层函数</li>
<li>内层函数对外层函数的局部变量进行了引用</li>
</ul>
<p>用途:<br><figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">const</span> cache = (<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</div><div class="line">		<span class="comment">//局部变量</span></div><div class="line">		<span class="keyword">const</span> store = &#123;&#125;;</div><div class="line">		<span class="keyword">return</span> &#123;</div><div class="line">			get(key)&#123;</div><div class="line">				<span class="keyword">return</span> store[key];</div><div class="line">			&#125;,</div><div class="line">			set(key,value)&#123;</div><div class="line">				store[key] = value;</div><div class="line">			&#125;</div><div class="line">			</div><div class="line">		&#125;</div><div class="line">&#125;)();</div><div class="line"></div><div class="line">cache.set(<span class="string">'a'</span>,<span class="string">'lalabu'</span>);</div><div class="line"><span class="built_in">console</span>.log(cache.get(<span class="string">'a'</span>));<span class="comment">//"lalabu"</span></div></pre></td></tr></table></figure></p>
<h4 id="高阶函数"><a href="#高阶函数" class="headerlink" title="高阶函数"></a>高阶函数</h4><p>概念:</p>
<blockquote>
<p>接受或者返回一个函数的函数称为高阶函数</p>
</blockquote>
<p>常见的高阶函数<code>Array.map , Array.reduce , Array.filter</code></p>
<p>Map(映射):</p>
<blockquote>
<p>映射是对集合而言的，即把集合的每一项都做相同的变换，产生一个新的集合</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div></pre></td><td class="code"><pre><div class="line"><span class="comment">// 数组中每一项加一，组成一个新数组</span></div><div class="line"></div><div class="line"><span class="comment">// 一般写法</span></div><div class="line"><span class="keyword">const</span> arr = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>];</div><div class="line"><span class="keyword">const</span> rs = [];</div><div class="line"><span class="keyword">for</span>(<span class="keyword">const</span> n <span class="keyword">of</span> arr)&#123;</div><div class="line">  rs.push(++n);</div><div class="line">&#125;</div><div class="line"><span class="built_in">console</span>.log(rs)</div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">// map改写</span></div><div class="line"><span class="keyword">const</span> arr = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>];</div><div class="line"><span class="keyword">const</span> rs = arr.map(<span class="function"><span class="params">n</span> =&gt;</span> ++n);</div></pre></td></tr></table></figure>
<p>上面一般写法，利用 for…of 循环的方式遍历数组会产生额外的操作，而且有改变原数组的风险</p>
<p>而 map 函数封装了必要的操作，使我们仅需要关心映射逻辑的函数实现即可，减少了代码量，也降低了副作用产生的风险。</p>
<h4 id="柯里化（Currying）"><a href="#柯里化（Currying）" class="headerlink" title="柯里化（Currying）"></a>柯里化（Currying）</h4><p>概念:</p>
<blockquote>
<p>给定一个函数的部分参数，生成一个接受其他参数的新函数;</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line"><span class="comment">// 获取目标文件对基础路径的相对路径</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">// 一般写法</span></div><div class="line"><span class="keyword">const</span> BASE = <span class="string">'/path/to/base'</span>;</div><div class="line"><span class="keyword">const</span> relativePath = path.relative(BASE, <span class="string">'/some/path'</span>);</div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">// _.parical 改写</span></div><div class="line"><span class="keyword">const</span> BASE = <span class="string">'/path/to/base'</span>;</div><div class="line"><span class="keyword">const</span> relativeFromBase = _.partial(path.relative, BASE);</div><div class="line"></div><div class="line"><span class="keyword">const</span> relativePath = relativeFromBase(<span class="string">'/some/path'</span>);</div></pre></td></tr></table></figure>
<p>通过 _.partial ，我们得到了新的函数 relativeFromBase ，这个函数在调用时就相当于调用 path.relative ，并默认将第一个参数传入 BASE ，后续传入的参数顺序后置。</p>
<p>本例中，我们真正想完成的操作是每次获得相对于 BASE 的路径，而非相对于任何路径。柯里化可以使我们只关心函数的部分参数，使函数的用途更加清晰，调用更加简单。</p>
<h4 id="组合-Composing"><a href="#组合-Composing" class="headerlink" title="组合(Composing)"></a>组合(Composing)</h4><p>概念:</p>
<blockquote>
<p>将多个函数的能力合并，创造一个新的函数</p>
</blockquote>
<p>同样你第一次见到他可能还是在 lodash 中，compose 方法（现在叫 flow）<br><figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div></pre></td><td class="code"><pre><div class="line"><span class="comment">// 数组中每个单词大写，做 Base64</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">// 一般写法 (其中一种)</span></div><div class="line"><span class="keyword">const</span> arr = [<span class="string">'pen'</span>, <span class="string">'apple'</span>, <span class="string">'applypen'</span>];</div><div class="line"><span class="keyword">const</span> rs = [];</div><div class="line"><span class="keyword">for</span>(<span class="keyword">const</span> w <span class="keyword">of</span> arr)&#123;</div><div class="line">  rs.push(btoa(w.toUpperCase()));</div><div class="line">&#125;</div><div class="line"><span class="built_in">console</span>.log(rs);</div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">// _.flow 改写</span></div><div class="line"><span class="keyword">const</span> arr = [<span class="string">'pen'</span>, <span class="string">'apple'</span>, <span class="string">'applypen'</span>];</div><div class="line"><span class="keyword">const</span> upperAndBase64 = _.partialRight(_.map, _.flow(_.upperCase, btoa));</div><div class="line"><span class="built_in">console</span>.log(upperAndBase64(arr));</div></pre></td></tr></table></figure></p>
<p>_.flow 将转大写和转 Base64 的函数的能力合并，生成一个新的函数。方便作为参数函数或后续复用。</p>

                <hr>
                <ul class="pager">
                    
                    <li class="previous">
                        <a href="/2017/06/09/2017-note/09.ES6字符串扩展/" data-toggle="tooltip" data-placement="top"
                           title="ES6字符串扩展">&larr; 上一页</a>
                    </li>
                    
                    
                    <li class="next">
                        <a href="/2017/06/03/carts/03.工具/" data-toggle="tooltip" data-placement="top"
                           title="工具列表">下一页 &rarr;</a>
                    </li>
                    
                </ul>
                <div class="comment">
                    <div id="cloud-tie-wrapper" class="cloud-tie-wrapper"></div>
                </div>
            </div>
            <div class="hidden-xs col-sm-3 toc-col">
                <div class="toc-wrap">
                    <ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#概念"><span class="toc-text">概念</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#特点"><span class="toc-text">特点</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#基本的函数式编程"><span class="toc-text">基本的函数式编程</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#链式优化"><span class="toc-text">链式优化</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#链式对比回调和Promise模式"><span class="toc-text">链式对比回调和Promise模式</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#常见的函数式编程"><span class="toc-text">常见的函数式编程</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#闭包-Closure"><span class="toc-text">闭包(Closure)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#高阶函数"><span class="toc-text">高阶函数</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#柯里化（Currying）"><span class="toc-text">柯里化（Currying）</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#组合-Composing"><span class="toc-text">组合(Composing)</span></a></li></ol></li></ol>
                </div>
            </div>
        </div>

        <div class="row">
            <!-- Sidebar Container -->

            <div class="
                col-lg-8 col-lg-offset-2
                col-md-10 col-md-offset-1
                sidebar-container">

                <!-- Featured Tags -->
                

                <!-- Friends Blog -->
                
            </div>
        </div>

    </div>
</article>
<!-- 网易云音乐-->

<iframe class="cloud-music" frameborder="no" border="0" marginwidth="0" marginheight="0" width=330 height=86 
    src="//music.163.com/outchain/player?type=2&amp;id=18803411&amp;auto=0&amp;height=66">
</iframe>
<!-- 网易云跟帖-->
<script src="https://img1.cache.netease.com/f2e/tie/yun/sdk/loader.js"></script>
<script>
var cloudTieConfig = {
  url: document.location.href, 
  sourceId: "",
  productKey: "40a8ee22b6084862a8907e6902e525fa",
  target: "cloud-tie-wrapper"
};
var yunManualLoad = true;
Tie.loader("aHR0cHM6Ly9hcGkuZ2VudGllLjE2My5jb20vcGMvbGl2ZXNjcmlwdC5odG1s", true);
</script>

<!-- Footer -->
<!-- Footer -->
<footer>
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1 text-center">
                <p class="copyright text-muted">
                    Copyright &copy; MillZhang 2017
                    <br>
                </p>
            </div>
        </div>
    </div>
</footer>

<!-- jQuery -->
<script src="/js/jquery.min.js"></script>

<!-- Bootstrap Core JavaScript -->
<script src="/js/bootstrap.min.js"></script>

<!-- Custom Theme JavaScript -->
<script src="/js/blog.js"></script>

<!-- async load function -->
<script>
    function async(u, c) {
      var d = document, t = 'script',
          o = d.createElement(t),
          s = d.getElementsByTagName(t)[0];
      o.src = u;
      if (c) { o.addEventListener('load', function (e) { c(null, e); }, false); }
      s.parentNode.insertBefore(o, s);
    }
</script>

<!-- jquery.tagcloud.js -->
<script>
    // only load tagcloud.js in tag.html
    if($('#tag_cloud').length !== 0){
        async("http://oritfw5nq.bkt.clouddn.com/jquery.tagcloud.js",function(){
            $.fn.tagcloud.defaults = {
                //size: {start: 1, end: 1, unit: 'em'},
                color: {start: '#bbbbee', end: '#0085a1'},
            };
            $('#tag_cloud a').tagcloud();
        })
    }
</script>

<!--fastClick.js -->
<script>
    async("//cdn.bootcss.com/fastclick/1.0.6/fastclick.min.js", function(){
        var $nav = document.querySelector("nav");
        if($nav) FastClick.attach($nav);
    })
</script>



<!--wechat title img-->
<img class="wechat-title-img" src="http://oritfw5nq.bkt.clouddn.com/avatar.jpg?imageslim">
<a id="backtop" class="border-bottom" href="javascript:;">回顶部</a>
<script type="application/javascript">
var docOuter = document.body.scrollTop ? document.body : document.documentElement;
var backToTop = function(rate) {
  var doc = document.body.scrollTop ? document.body : document.documentElement;
  var scrollTop = doc.scrollTop;
  var top = function() {
    scrollTop = scrollTop + (0 - scrollTop) / (rate || 2);
    if (scrollTop < 1) {
      doc.scrollTop = 0;
      return;
    }
    doc.scrollTop = scrollTop;
    // 动画gogogo!
    requestAnimationFrame(top);
  };
  top();
};
var topBtn = document.getElementById('backtop'),
    docTop = docOuter.scrollTop;
if(docTop>=300){
  topBtn.style.opacity = 1;
}

topBtn.onclick = function() {
  backToTop(12)
}
window.onscroll = function(e) {
  var doc = document.body.scrollTop ? document.body : document.documentElement;
  var scrollTop = doc.scrollTop;
  if (scrollTop >= 300) {
    topBtn.style.opacity = 1;
  } else {
    topBtn.style.opacity = 0;
  }
}
</script>
</body>

</html>
